package org.ycx.doc.dao.mapper;

import org.apache.ibatis.jdbc.SQL;

import java.util.List;
import java.util.Map;

public class IDocGroupSqlProvider {

    public String findProjectByUserProvider(Map<String, Object> parameter){
        StringBuffer sql = new StringBuffer();
        sql.append("select dp.* ");
        sql.append(" from doc_group dg,doc_group_project dgp,doc_group_user dgu,doc_project dp  ");
        if(parameter.containsKey("rids")){
            List<Integer> rids = (List<Integer>) parameter.get("rids");
            if(rids.size()>0){
                StringBuffer sb = new StringBuffer();
                for (Integer rid:rids) {
                    sb.append(",");
                    sb.append(rid);
                }
                sb.append(")");
                sql.append("where dg.GROUP_ID = dgu.GROUP_ID and dgp.GROUP_ID = dg.GROUP_ID and dgp.APP_ID=dp.APP_ID and dgu.USER_ID=#{uid} and dgu.role in ("+sb.substring(1));
            }
        }else{
            sql.append("where dg.GROUP_ID = dgu.GROUP_ID and dgp.GROUP_ID = dg.GROUP_ID and dgp.APP_ID=dp.APP_ID and dgu.USER_ID=#{uid}");
        }
        return sql.toString();
    }
}
